<template>
  <div class="content">
    <v-chart :option="chartOption" autoresize></v-chart>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default {
  components: {},
  /**
   * @title  legend标题
   * @dataX  X轴数据
   * @dataY  y轴数据
   * @color 折线颜色
   * @areaStyleColor 折线下渐变色 开始颜色-结束颜色
   */
  props: {
    title: {
      type: String,
      default() {
        return "";
      },
    },
    dataX: {
      type: Array,
      default() {
        return ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "13", "13"];
      },
    },
    dataY: {
      type: Array,
      default() {
        return [
          "1200",
          "1400",
          "1008",
          "1411",
          "1026",
          "1288",
          "1300",
          "800",
          "1100",
          "1000",
          "1118",
          "1322",
        ];
      },
    },
    color: {
      type: Array,
      default() {
        return ["#FFA901"];
      },
    },
    areaStyleColor: {
      type: Array,
      default() {
        return ["#FFF4E0", "#FFFFFF"];
      },
    },
  },
  data() {
    return {
      chartOption: {
        grid: {
          top: "15%",
          left: "10%",
          right: "0%",
          bottom: "1%",
          containLabel: true,
        },
        color: this.color,
        legend: {
          icon: "circle",
          //   orient: "vertical",
          x: "right", //可设定图例在左、右、居中
          y: "top", //可设定图例在上、下、居中
          padding: [6, 10, 12, 0], //可设定图例[距上方距离，距右方距离，距下方距离，距左方距离]
          itemWidth: 16, // 宽
          itemHeight: 16, // 高
          textStyle: {
            //图例文字的样式
            color: "#666666",
            fontSize: 14,
          },
          data: [this.title],
        },
        xAxis: {
          type: "category",
          axisTick: {
            show: true,
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#D0D3D9",
            },
          },
          axisLabel: {
            //x轴文字的配置
            show: true,
            textStyle: {
              color: "#707070",
            },
          },
          data: this.dataX,
          boundaryGap: true,
        },
        yAxis: {
          type: "value",
          name: "单位:  元 /公斤",
          // boundaryGap: ['20%', '50%'],// 坐标轴两边留白策略 [左右，上下]
          nameTextStyle: {
            color: "#666666", //  字体颜色
            fontSize: 14, //  字体大小
            padding: [0, 0, 12, 0], //  内填充
          },
          splitLine: {
            show: true,
            lineStyle: {
              type: "dashed", // y轴分割线类型
            },
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisLabel: {
            show: true,
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            show: true,
            status: "shadow",
            z: -1,
            shadowStyle: {
              color: "transparent",
            },
            type: "shadow",
          },
        },
        series: [
          {
            name: this.title,
            type: "line",
            smooth: true,
            showSymbol: true,
            symbol: "circle",
            symbolSize: 6,
            data: [],
            label: {
              show: true,
              formatter: function (data) {
                return data.value;
              },
              color: this.color[0],
            },
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: this.areaStyleColor[0],
                    },
                    {
                      offset: 1,
                      color: this.areaStyleColor[1],
                    },
                  ],
                  false
                ),
              },
            },
            //设置折线图颜色
            itemStyle: {
              normal: {
                lineStyle: {
                  color: this.color[0],
                },
              },
            },
            lineStyle: {
              normal: {
                width: 2,
              },
            },
          },
        ],
      },
    };
  },
  created() {
    this.chartOption.series[0].data = this.dataY;
  },
  mounted() {},
  methods: {},
};
</script>
<style lang="less" scoped>
.content {
  height: 100%;
  width: 100%;
}
</style>